<template>
  <div class="vod-course">
    <div class="course-item" v-for="item in courses" :key="item.id" @click="goToDetail(item.id)">
        <div class="course-thumb"><img v-lazy="item.thumb" alt=""></div>
        <div class="course-content">
          <div class="course-title">{{item.title}}</div>
          <div class="course-info" v-if="$route.name == 'study'">
            <div class="course-sub">订阅时间{{item.published_at | formatTime}}</div>
          </div>
          <div class="course-info" v-else>
            <div class="course-sub">{{item.user_count}}人已订阅</div>
            <div class="course-charge" :class="{free: item.is_free}" v-html="item.is_free ? '免费' : `<span>￥</span>${item.charge}`"></div>
          </div>
        </div>
      </div>
  </div>
</template>

<script>
export default {
  props: ['courses'],
  methods: {
    goToDetail(id) {
      this.$router.push({ path: '/vod/detail', query: { id } });
    },
  },
};
</script>

<style lang="less" scoped>
.vod-course {
  padding: 12px 16px;
  .course-item {
    display: flex;
    margin-bottom: 14px;
    &:last-child {
      margin-bottom: 0;
    }
    .course-thumb {
      img {
        width: 120px;
        height: 88px;
        border-radius: 4px;
      }
    }
    .course-content {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      padding: 4px 0;
      margin-left: 8px;
      .course-title {
        font-size: 15.2px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
      }
      .course-info {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .course-sub {
          color: #999;
          font-size: 12px;
        }
        .course-charge {
          color: #ff5858;
          font-size: 18px;
          font-weight: 700;
          &.free {
            color: #52c41a;
            font-size: 14px;
          }
        }
      }
    }
  }
}
</style>
